/*
uniapp内置了vuex的，直接可引入 使用
1：导入


*/
import cart from './modules/cart'
import user from './modules/user'
// 1：导入
import Vuex from 'vuex'
import persistedstate from 'vuex-persistedstate'
// 2:注册
import Vue from 'vue'
Vue.use(Vuex)
// 3:实例化
const store = new Vuex.Store({
  state: {},
  mutations: {},
  actions: {},
  getters: {},
  modules: {
    cart,
    user
  },
  plugins: [
    persistedstate({
      paths: ['cart.num', 'cart.cartList', 'user.address', 'user.token', 'user.userInfo'],
      storage: {
        getItem: (key) => {
          return uni.getStorageSync(key)
        },
        setItem: (key, value) => {
          uni.setStorageSync(key, value)
        },
        removeItem: (key) => {
          uni.removeStorageSync(key)
        }
      }
    })
  ]
})
// 4:暴露出去
export default store

// 持久化插件:vuex-persistedstate